package com.atfcm.queue;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.LinkedList;
import java.util.PriorityQueue;

/**
 * @Author 96534
 * @create 2025/3/27 17:45
 */
public class T_数据流中的第K大元素 {
    PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
    int kn;

    public void KthLargest(int k, int[] nums) {
        this.kn = k;
        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
            if (queue.size() > k) {
                queue.poll();
            }
        }
    }

    public int add(int val) {
        queue.offer(val);
        if (queue.size() > this.kn) {
            queue.poll();
        }

        return queue.peek();
    }
}

class MyPriorityQueue {
    int[] array;
    MyPriorityQueue(int size) {
        this.array = new int[size];
    }


}
